使用 gdrive 自动备份你的服务器

阅读量:1513 字数:1175 阅读时间:2min

若果你的服务器没有自动备份的功能,那等到数据丢失的那一刻再后悔也来不及了。Google Drive 是谷歌公司推出的一项在线云存储服务。gdrive 是一款开源、跨平台的命令行工具可与 Google Drive 进行关联。本文列出通过 gdrive 和 Google Drive 来使你的服务器拥有自动备份功能的详细步骤。

github

前提

  1. 你需要拥有一个 Google Drive 账号。请前往 http://drive.google.com 进行注册,新用户将有 15GB 的免费储存空间。

Google Drive

  1. 为您的服务器安装 zip, unzip, wget 和 crontab

参考命令:

yum install -y unzip zip

开始使用

  1. 前往 github 找到符合的程序版本,如 Linux 64-bit,并复制下载链接。
  2. 下载文件到 /usr/bin
wget -p /usr/bin -o "gdrive" "下载地址"
  1. 增加运行权限
chmod 777 /usr/bin/gdrive
  1. 授权并输入 Google Drive API 凭据
gdrive about

执行上述命令后,打开列出的网址并完成授权,键入提供的 Google Drive API 凭据。

  1. 获取文件夹 Hash

登录 Google Drive,创建一个文件夹用于存放所以备份。进入文件夹,留意网址 folder/ 后的即为该文件夹的 hash

hash

  1. 创建脚本文件
touch /root/gdrive_backup.sh
chmod 777 /root/gdrive_backup.sh

脚本文件内容:

#!/bin/sh
nowdate=$(date +"%Y-%m-%d")
if [ "$success" == "0" ];then
exit;
fi;
cd 需要备份的目录
zip -r -P "压缩包密码" $nowdate.zip ./*
floder_hash=$(gdrive mkdir -p "文件夹Hash" $nowdate | awk '{print $2}')
gdrive upload -p "$floder_hash" $nowdate.zip
rm -rf 需要备份的目录/$nowdate.zip

注意修改中文部分。

  1. 使用 Crontab 定时执行 gdrive_backup.sh
crontab -e

完成

很快便能在你的 Google Drive 里看到服务器的备份了。

done

上一篇:PHP Project: DailyLife

Introduction Wanna have a private zone to record some special moment, some unforgettable memory? Wanna have a quite place to speak-out-loud but not to afraid of the mass followers of your social med

下一篇:2017 年度总结

这是一份姗姗来迟的年度报告,写这份报告时我已经寒假放假坐在自己小窝里了。2017 我是我 18 岁的一年,是我唯一的 18 岁,我必须记住这一年。一路走来,有喜有悲,但我感谢一切。一年的经历与感悟太多,只能用这简短的文字和几张图片来一个大致的总结。 年度大事 7月 高考 9月 军训 10月 搬家 电子产品 4月 Nexus 6 7月 MacBook

雁过留痕,风过留声

目 录